package com.qf.dao;

import com.qf.pojo.Address;
import com.qf.util.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 千锋健哥
 */
public class AddresDaoImpl implements AddressDao{

    private QueryRunner queryRunner = new QueryRunner(DataSourceUtil.getDataSource());

    @Override
    public List<Address> findList(Integer uid) {
        try {
            String sql = "select * from tb_address where uid=?";
            List<Address> list = queryRunner.query(sql, new BeanListHandler<Address>(Address.class), uid);
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Address findById(Integer id) {
        try {
            String sql = "select * from tb_address where id=?";
            Address address = queryRunner.query(sql, new BeanHandler<Address>(Address.class), id);
            return address;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
